package com.sws.web.controller.ry_rongyue.wx;

import com.sws.common.core.domain.AjaxResult;
import com.sws.wx_msg_push.dto.ReservationReminderDTO;
import com.sws.wx_msg_push.service.ReservationReminderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预约提醒测试控制器
 */
@RestController
@RequestMapping("/reservation/reminder/test")
@Slf4j
public class ReservationReminderTestController {

    @Autowired
    private ReservationReminderService reminderService;

    /**
     * 测试查询未来预约
     */
    @GetMapping("/query/{minutes}")
    public AjaxResult testQuery(@PathVariable("minutes") Integer minutes) {
        if (minutes == null || minutes < 1 || minutes > 1440) {
            return AjaxResult.error("时间范围必须在1-1440分钟之间");
        }
        
        log.info("测试查询未来{}分钟内的预约", minutes);
        
        try {
            List<ReservationReminderDTO> reservations = reminderService.getUpcomingStaffReservations(minutes);
            return AjaxResult.success("查询成功", reservations);
        } catch (Exception e) {
            log.error("测试查询预约异常", e);
            return AjaxResult.error("测试查询预约异常: " + e.getMessage());
        }
    }
    
    /**
     * 测试创建一个模拟预约并发送提醒
     */
    @PostMapping("/send-mock")
    public AjaxResult testSendMock(@RequestParam("openid") String openid) {
        if (openid == null || openid.isEmpty()) {
            return AjaxResult.error("openid不能为空");
        }
        
        log.info("测试发送模拟预约提醒到openid: {}", openid);
        
        try {
            // 创建一个模拟预约
            ReservationReminderDTO mockReservation = new ReservationReminderDTO();
            mockReservation.setReservationId(999L);
            mockReservation.setCustomerName("测试客户");
            mockReservation.setCustomerGender(1); // 男性
            mockReservation.setOpenid(openid);
            mockReservation.setServiceContent("测试服务项目");
            mockReservation.setStaffName("测试技师");
            mockReservation.setRoomNo("测试房间");
            mockReservation.setAppointmentTime(LocalDateTime.now().plusMinutes(30));
            
            // 发送提醒
            AjaxResult result = reminderService.sendReservationReminder(mockReservation);
            return result;
            
        } catch (Exception e) {
            log.error("测试发送模拟预约提醒异常", e);
            return AjaxResult.error("测试发送模拟预约提醒异常: " + e.getMessage());
        }
    }
} 